This page last changed on Jun 04, 2009 by kgomes.

Maven Presentations

Maven Presentation to Software Discussion Group

Using the internal MBARI repository from a Maven 2 project

The internal MBARI repository is managed by Archiva. It should be the preferred and only repository referenced by your internal MBARI projects. It is a caching proxy, which means it fetches and stores jars from other repositories as they are referenced by your projects. This helps ensure that your projects dependencies don't disappear like the could from externally controlled repositories. If you need jars from a 3rd party repository that aren't available via Archiva, contact brian@mbari.org to have the repository added to our Archiva setup.

Referencing the Repository

To include the internal MBARI repository in your Maven build, edit your pom.xml to include the MBARI repository location:

<?xml version="1.0" encoding="UTF-8"?>
<!-- pom.xml -->
<project>
  ...
  <distributionManagement>
    <repository>
      <id>internal</id>
      <url>dav:http://seaspray.shore.mbari.org:8082/archiva/repository/internal/</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>dav:http://seaspray.shore.mbari.org:8082/archiva/repository/snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

  <repositories>
    <repository>
      <id>internal</id>
      <name>Archiva Managed Internal Repository</name>
      <url>http://seaspray.shore.mbari.org:8082/archiva/repository/internal/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>snapshots</id>
      <name>Archiva Managed Snapshot Repository</name>
      <url>http://seaspray.shore.mbari.org:8082/archiva/repository/snapshots/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  ...
</project>

Using the external MBARI repository from a Maven 2 project

Referencing the Repository

To include the MBARI repository in your Maven build, edit your pom.xml to include the MBARI repository location:

<?xml version="1.0" encoding="UTF-8"?>
<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  ...
  <repositories>

    <!-- Include this repository block -->
    <repository>
      <id>mbari</id>
      <name>MBARI Repository</name>
      <url>http://oceana.shore.mbari.org/maven2</url>
    </repository>
  ...
  </repositories>
  ...
</project>

Including a Dependency from the Repository

Once the MBARI repository is included in you build, you can browse the repository to see what projects are available (just go to http://oceana.shore.mbari.org/maven2). If you find a dependency you need you can reference it in your pom.xml. Here's an example...

<?xml version="1.0" encoding="UTF-8"?>
<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  ...
  <dependencies>
    ...
    <!-- Include this dependency block -->
    <dependency>
      <groupId>qt4j</groupId>
      <artifactId>qt4j</artifactId>
      <version>0.5</version>
    </dependency>
    ...
  </dependencies>
  ...
</project>

Putting a Dependency into the Repository

The easiest way to put a dependency into the repository is to setup a Maven build file (i.e. pom.xml). In pom.xml add the following distributionManagement information:

<?xml version="1.0" encoding="UTF-8"?>
<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>qt4j</groupId> <!-- Name of your project or group (e.g. org.mbari.<projectName>) -->
  <artifactId>qt4j</artifactId> <!-- name of you project -->
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version> <!-- The version number of your project. Here we use a SNAPSHOT build -->
  <name>QT4J</name> <!-- Name of your project -->
...
  <distributionManagement> 
      <repository> 
        <id>mbari-repository</id> 
        <name>MBARI Repository</name> 
        <url>scp://oceana.shore.mbari.org/var/www/html/maven2</url> 
      </repository> 
  </distributionManagement>
</project>

Executing mvn deploy will put your build jar at http://oceana.shore.mbari.org/maven2/<groupId>/<artifactId>/<version>/<artifactId>-<version>.jar. In the example here it would put it into http://oceana.shore.mbari.org/maven2/qt4j/qt4j/1.0-SNAPSHOT/

Publishing Maven generated web sites

Maven can generate a web site for a default web site for you. You can view samples of the currently published projects at http://oceana.shore.mbari.org/projects. It's not very interesting, however, it is a very simple way to publish the javadoc, sources and auto-generated reports. To do so modify your pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    ...
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <configuration>
                    <targetJdk>1.5</targetJdk>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
    <distributionManagement>
        ...
        <site>
            <id>oceana.shore.mbari.org</id>
            <url>scp://oceana.shore.mbari.org/var/www/html/projects/${project.name}</url>
        </site>
    </distributionManagement>
</project>

Then run mvn javadoc:javadoc site:site site:deploy. This will build the javadocs, create a site with some useful reports, then publish the site (using scp) to oceana in the correct location.

Project Specific Maven Repositories

Some projects may need to be configured differently for different deployment locations. For example, VARS is configured differently for each ship and shore. These specific configurations are stored in Maven repositories in http://oceana.shore.mbari.org/maven2-prj. Each directory listed there is a different repository. Here's an example of how to include the projects configured for Eye-in-the-sea.

<!-- EITS repository -->
    <repository>
      <id>mbari-eits</id>
      <name>MBARI-EITS Repository</name>
      <url>http://oceana.shore.mbari.org/maven2-prj/eits</url>
    </repository>

Using the external MBARI repository from an Ant project using Maven

Maven repositories can be used from Ant build scripts using Maven's antlib. To do this you must have both Maven and Ant installed.

Bootstrapping antlib

To bootstrap antlib into your projects (so users can build without having to install antlib) modify your build.xml file like so:

<?xml version="1.0" ?>
<!-- $Id: build.xml,v 1.21 2007/01/05 01:04:43 brian Exp $ -->
<project 
    name="YourProjectName" 
    default="init" 
    basedir="." 
    xmlns:artifact="antlib:org.apache.maven.artifact.ant">
    
    ... 

    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         Install the Maven artifact and configure project properties
    -->

    <property name="artifact.jar.dir" value="${basedir}/.ant" />
    <property name="artifact.jar.file" value="${artifact.jar.dir}/maven.artifact-ant-2.0.2-dep.jar" />
    <mkdir dir="${artifact.jar.dir}"/>
    <!--
       download maven antlib from web site so that it can be used even without any
       special installation
     -->
    <available file="${artifact.jar.file}" property="artifact.exists"/>
    <echo message="Installing Maven Antlib..."/>
    <get src="http://www.apache.org/dist/maven/binaries/maven-artifact-ant-2.0.2-dep.jar"
         dest="${artifact.jar.file}" usetimestamp="true" ignoreerrors="${artifact.exists}"/>

    <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant">
        <classpath>
            <pathelement location="${artifact.jar.file}" />
        </classpath>
    </typedef>
    
    <!-- 
        Configure properties based on pom.xml and typical Maven build structure.
        Modify this for your own project structure
    -->
    <artifact:pom id="pom" file="pom.xml" />
    <property name="version" value="${pom.version}" />
    <property name="project" value="${pom.artifactId}" />
    <property name="build" value="${pom.build.directory}" />
    <property name="lib" value="${build}/lib" />

    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    init
        Sets up the project for build

    -->
    <target name="init" description="Create the build directory structure">
        <!-- Create the timestamp -->
        <tstamp/>
        
        <!-- Create the directory build structure used by compile -->
        <mkdir dir="${build}"/>
        <mkdir dir="${lib}"/>
        
        <!-- Copy dependencies to target/lib -->
        <echo>Finding dependencies of ${pom.artifactId}-${version}</echo>
        <artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
            <pom refid="pom"/>
        </artifact:dependencies>
        <copy todir="${lib}" verbose="true">
            <fileset refid="dependency.fileset" />
            <mapper type="flatten" />
        </copy>
            
        ...
    </target>

Using the external MBARI repository from an Ant project using Ivy

Maven repositories can be used from Ant build scripts using Ivy.

Referencing the repository

In the directory containing the ant build file, build.xml, create a file called ivyconf.xml. ivyconf.xml tells Ivy where to look for dependencies. The contents of the file will look something like:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ivyconf.xml -->
<ivyconf>
  <conf defaultResolver="default" checkUpToDate="true"/>
  <resolvers>
    <ivyrep name="libraries"/>
    <chain name="default">
      <url name="ibiblio-maven2" m2compatible="true">
        <artifact pattern="http://www.ibiblio.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"/>
      </url>
      <!-- Below is the reference to MBARI's repository -->
      <url name="mbari-maven2" m2compatible="true">
        <artifact pattern="http://oceana.shore.mbari.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"/>
      </url>
      <ivyrep name="ivyrep"/>
    </chain>
  </resolvers>
</ivyconf>

Including a Dependency from the Repository

In the directory containing build.xml, create a file called ivy.xml. ivy.xml tells Ivy what dependencies to include in your build. Here's an example of it's contents:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://www.ivyrep.org/ivy-doc.xsl"?>
<!-- ivy.xml -->
<ivy-module version="1.4"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.jayasoft.org/misc/ivy/ivy.xsd">
  <info organisation="MBARI" module="aved-db" />
  <dependencies>
    <dependency org="apache" name="commons-logging" rev="1.1" />
    <dependency org="foxtrot" name="foxtrot" rev="2.0"/>
    <dependency org="junit" name="junit" rev="4.1" />
    <!-- The line below is a dependency from MBARI's repository -->
    <dependency org="qt4j" name="qt4j" rev="1.0-SNAPSHOT" />
  </dependencies>
</ivy-module>

Using Ivy from Ant

The code below will fetch Ivy for you. SO you do not need install any additional software in order to get you build to work. In your ant build file include the following:

<?xml version="1.0" ?>
<!-- $Id: build.xml,v 1.14 2006/11/22 00:17:10 brian Exp $ -->
<project name="qt4j" default="all" basedir="." xmlns:ivy="antlib:fr.jayasoft.ivy.ant">

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    IVY setup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <property name="ivy.install.version" value="1.4.1" />
    <property name="ivy.jar.dir" value="${basedir}/.ivy" />
    <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy-${ivy.install.version}.jar" />

  
    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ivy.install        
        this target is not necessary if you put ivy.jar in your ant lib directory
        if you already have ivy 1.4 in your ant lib, you can simply remove this
        target and the dependency the 'go' target has on it
    -->
    <target name="ivy.install" description="Install ivy">
        <mkdir dir="${ivy.jar.dir}"/>
        <!-- 
          download Ivy from web site so that it can be used even without any 
          special installation 
        -->
        <available file="${ivy.jar.file}" property="ivy.exists"/>
        <echo message="Installing ivy..."/>
        <get src="http://www.jayasoft.org/downloads/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
                dest="${ivy.jar.file}" usetimestamp="true" ignoreerrors="${ivy.exists}"/>
         
        <!-- 
          try to load ivy here from local ivy dir, in case the user has not already dropped
          it into ant's lib dir (note that the latter copy will always take precedence).
          We will not fail as long as local lib dir exists (it may be empty) and
          ivy is in at least one of ant's lib dir or the local lib dir. 
        -->
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="fr/jayasoft/ivy/ant/antlib.xml"
                uri="antlib:fr.jayasoft.ivy.ant" classpathref="ivy.lib.path"/>
        <ivy:retrieve />
    </target>
  

    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ivy.clean              
    -->
    <target name="ivy.clean" description="Clean the ivy installation from ${ivy.jar.dir}">
    <!-- delete the lib directory -->
        <delete dir="${ivy.jar.dir}" />
    </target>

    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ivy.clean-cache              
    -->
    <target name="ivy.clean-cache" description="Clean the ivy cache">
        <delete dir="${user.home}/.ivy/cache"/>
    </target>

   ...

</project>

Calling ant ivy.install will fetch all the dependencies from the web and put them into the lib directory of your project.


Document generated by Confluence on Feb 03, 2026 16:22